<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
    
  
  <link href="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<link href="/lh706.github.io/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="JavaScript,总结," />








  <link rel="shortcut icon" type="image/x-icon" href="/lh706.github.io/favicon.ico?v=5.1.1" />






<meta name="description" content="关于1.要注意方法属性属于不同的对象,window,或者HTMLElement对象—">
<meta name="keywords" content="JavaScript,总结">
<meta property="og:type" content="article">
<meta property="og:title" content="DOM总结">
<meta property="og:url" content="https://lh706.github.io/lh706.github.io/2017/05/20/DOM总结/index.html">
<meta property="og:site_name" content="Albert的blog">
<meta property="og:description" content="关于1.要注意方法属性属于不同的对象,window,或者HTMLElement对象—">
<meta property="og:updated_time" content="2017-05-20T08:14:51.059Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="DOM总结">
<meta name="twitter:description" content="关于1.要注意方法属性属于不同的对象,window,或者HTMLElement对象—">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/lh706.github.io/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://lh706.github.io/lh706.github.io/2017/05/20/DOM总结/"/>





  <title>DOM总结 | Albert的blog</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/lh706.github.io/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Albert的blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/lh706.github.io/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/lh706.github.io/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/lh706.github.io/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-tags " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://lh706.github.io/lh706.github.io/lh706.github.io/2017/05/20/DOM总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Albert">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/lh706.github.io/my.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Albert的blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">DOM总结</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-20T16:14:15+08:00">
                2017-05-20
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="关于"><a href="#关于" class="headerlink" title="关于"></a>关于</h3><p>1.要注意方法属性属于不同的对象,window,或者HTMLElement对象—</p>
<a id="more"></a>
<h3 id="元素选择器"><a href="#元素选择器" class="headerlink" title="元素选择器"></a>元素选择器</h3><p>直接选择:<br>通过id—getElementById<br>通过标签类型—getElementByTagName<br>通过类—getElementByClassName<br>通过name—getElementByName<br>通过css选择器,匹配的第一个元素—querySelector<br>通过css选择器,匹配的所用元素—querySelectorAll</p>
<p>父元素:<br>父元素—parentNode<br>子元素:<br>子元素集合—childNode<br>第一个子元素—firstChild<br>最后一个子元素—lastChild<br>兄弟元素<br>后面的兄弟元素—nextSiblings<br>前面的兄弟元素—previousSiblings</p>
<p>*全局选择:<br>body<br>head<br>images<br>forms</p>
<p>*其他选择:<br>获得焦点的元素—activeElement<br>embed元素—embeds</p>
<h3 id="属性操作"><a href="#属性操作" class="headerlink" title="属性操作"></a>属性操作</h3><p>类的列表—className<br>添加类—add<br>移除类—remove???<br>添加或移除类—toggle<br>获取元素属性—attributes<br>返回指定属性的值—getAttribute<br>移除属性—removeAttribute<br>设置属性—setAttribute<br>返回数据—dataset<br>能否使用—disabled<br>隐藏—hidden<br>id值—id<br>标签名—TagName</p>
<p>*css其他属性<br>返回css规则集合—cssRules<br>删除一条规则—deletRule<br>插入规则—inserRule<br>获取样式表—styleSheets(多个样式表时,这是个数组)</p>
<p>关键全局属性:<br>cookie—cookie<br>*浏览历史—history<br>    在浏览器里后退一步—back<br>    前进一步—forward<br>    转到—go<br>    历史的项目数量—length<br>    添加项目—pushState<br>    替换当前项目—replaceState<br>加载文档状态—readyState</p>
<p>*全局属性:<br>字符集—charset<br>文档兼容性模式—compatMode<br>浏览器默认字符编码—defaultCharset<br>window对象—defaultView<br>返回自己—self(window.self)<br>文本方向—dir<br>文档最后修改时间—lastModified<br>lang属性—lang<br>tab选中顺序—tabindex<br>对DOM实现的信息—implementation对象 (hasFeature判断功能实现情况)</p>
<p>*域名相关:<br>URL信息—location<br>文档域名—domain<br>导航到指定URL上—assign<br>URL的锚(#号后面)—hash<br>主机号和端口号—host<br>主机名—hostname<br>端口号—port<br>地址—href<br>路径—pathname<br>协议—protocol<br>重新加载当前文档—reload<br>清除当前文档并导航至指定文档—replace<br>将相对url解析为绝对url—resolveURL<br>url的查询部分(问号后面)—search</p>
<p>*长宽距离类<br>屏幕对象—screen<br>    视口高度—availHeight<br>    视口宽度—availWidth<br>    颜色深度—colorDepth<br>    屏幕高度—height<br>    屏幕宽度—width<br>窗口高度—innerHeight<br>窗口宽度—innerWidth<br>包括边框等高度—outerHeight<br>包括边框宽度—outerWidth</p>
<p>向左滚动距离—pageXOffset<br>向右滚动距离—pageYOffset<br>相对当前位置滚动—scrollBy<br>滚动到指定位置—scrollTo</p>
<p>左边窗口与屏幕的距离—screenLeft/screenX<br>上边缘窗口与屏幕距离—screenTop/screenY</p>
<p>相对位置—compareDocumentPosition</p>
<h3 id="事件"><a href="#事件" class="headerlink" title="事件"></a>事件</h3><p>添加事件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">addEventListener(event, function, useCapture)</div><div class="line">event---事件,不用on前缀</div><div class="line">useCapture---布尔值,false默认,冒泡期句柄执行,true在捕获期间执行</div><div class="line">兼容ie9往上</div></pre></td></tr></table></figure></p>
<p>即将/失去键盘焦点—focusout/blur<br>即将/获得键盘焦点—focusin/focus<br>按下按键—keydown<br>敲击按键—keypress<br>释放按键—keyup<br>双击—dblclick<br>单击—click<br>鼠标按下—mousedown<br>鼠标释放—mouseup<br>光标进入(包括下属元素)—mouseenter<br>光标移除(包括下属元素)—mouseleave<br>移动—mousemove<br>光标进入(不包括下属元素)—mouseover<br>光标移除(不包括下属元素)—mouseout</p>
<p>文档或资源<br>    加载中止—onabor<br>    错误—onerrror<br>    完成—onload</p>
<p>窗口大小改变—onresize<br><em>打印文档后—onafterprint
</em>打印文档前(print调用后)—onbeforeprint<br>文档加载状态改变—readstatechange<br>*重置时—reset<br>提交时—submit</p>
<h3 id="元素操作"><a href="#元素操作" class="headerlink" title="元素操作"></a>元素操作</h3><p>添加子元素—appendChild<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">var a=create(p);---创建一个p标签</div><div class="line">for(..)&#123;</div><div class="line">    body.appendChild(a)---循环插入---只会插入一个</div><div class="line">    a是同一个对象;</div><div class="line">&#125;</div><div class="line">for(...)&#123;</div><div class="line">    var a=create(p);</div><div class="line">    body.appendChild(a)---每次都是新的a,循环插入</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>移除子元素—removeChild<br>替换子元素—replaceChild</p>
<p>克隆—cloneNode<br>内容—innerHTML<br>标签与内容—outerHTML<br>创建元素—createElement<br>创建text对象—createTextNode<br>    文本—data<br>    length—文本数量<br>    末尾添加字符串—appendDate<br>    指定位置添加字符串—insertData<br>    移除一定数量文本—deleteData<br>    替换指定文本—replaceData<br>插入对象—insertAdjacentHTML()</p>
<h3 id="判断类"><a href="#判断类" class="headerlink" title="判断类"></a>判断类</h3><p>是否有子元素—hasChildNodes<br>是否是指定类—contains()<br>是否有指定属性—hasAttritube</p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>普通弹出—alert<br>带确认取消的弹出—confirm<br>带输入的弹出—prompt<br>一次性计时器—setTimeout<br>计数器—setInterval<br>撤销计时器—clearInterval/Timeout</p>
<p>*其他的其他<br>打开浏览器上下文环境window—oprner<br>给另一个文档发消息—postMessage<br>提示打印—print<br>关闭窗口—close<br>停止载入—stop<br>返回上层window—top</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/lh706.github.io/tags/JavaScript/" rel="tag"># JavaScript</a>
          
            <a href="/lh706.github.io/tags/总结/" rel="tag"># 总结</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/lh706.github.io/2017/05/20/axios/" rel="next" title="axios">
                <i class="fa fa-chevron-left"></i> axios
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/lh706.github.io/2017/05/20/事件/" rel="prev" title="事件总结">
                事件总结 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/lh706.github.io/my.jpg"
               alt="Albert" />
          <p class="site-author-name" itemprop="name">Albert</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/lh706.github.io/archives">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/lh706.github.io/tags/index.html">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/lh706" target="_blank" title="GitHub">
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/liang-da-shu-shu" target="_blank" title="知乎">
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#关于"><span class="nav-number">1.</span> <span class="nav-text">关于</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#元素选择器"><span class="nav-number">2.</span> <span class="nav-text">元素选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#属性操作"><span class="nav-number">3.</span> <span class="nav-text">属性操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#事件"><span class="nav-number">4.</span> <span class="nav-text">事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#元素操作"><span class="nav-number">5.</span> <span class="nav-text">元素操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#判断类"><span class="nav-number">6.</span> <span class="nav-text">判断类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其他"><span class="nav-number">7.</span> <span class="nav-text">其他</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Albert</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/fastclick/1.0.6/fastclick.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazyload/1.9.3/jquery.lazyload.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.ui.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.pack.js"></script>

  
  <script type="text/javascript" src="/lh706.github.io/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/lh706.github.io/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/lh706.github.io/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/lh706.github.io/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/lh706.github.io/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/lh706.github.io/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

</body>
</html>
